package com.etc.order.frontend.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.etc.order.common.domain.ProductCategory;
import com.etc.order.common.domain.ProductInfo;
import com.etc.order.common.dto.SimpleDTO;
import com.etc.order.common.service.ProductCategoryService;
import com.etc.order.common.service.ProductInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class ProductInfoController {
    @Resource
    @Reference
    private ProductInfoService productInfoService;

    @Resource
    @Reference
    private ProductCategoryService productCategoryService;

    @GetMapping("/product/listByCategoryType")
    @ResponseBody
    public SimpleDTO getProductInfoByCategoryType(int categoryType) {
        List<ProductCategory> categories = productCategoryService.findByCategoryType(categoryType);
        if (categories.size() == 0) {
            return new SimpleDTO(1, "类目不存在", null);
        }
        List<ProductInfo> productInfoList = productInfoService.getFoods(categoryType);

        return new SimpleDTO(0, "成功", productInfoList);
    }
}
